package com.zhongkai.dao.config;

import java.util.List;

import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import com.zhongkai.dao.BaseDao;
import com.zhongkai.model.config.Role;

@Component
public class RoleDAO extends BaseDao {

	public void save(Role role) throws Exception {
		getHibernateTemplate().save(role);
	}
	
	public void update(Role role) throws Exception {
		getHibernateTemplate().update(role);
	}
	
	public void saveOrUpdate(Role role) throws Exception {
			getHibernateTemplate().saveOrUpdate(role);
	}
	
	public void saveOrUpdateAll(List<Role> roleList) throws Exception {
		getHibernateTemplate().saveOrUpdateAll(roleList);
	}
	
	public void delete(Role role) throws Exception {
			getHibernateTemplate().delete(role);
	}

	public Role findById(java.lang.Integer id) throws Exception {
		return (Role) getHibernateTemplate().get("com.zhongkai.model.config.Role", id);
	}

	public List<Role> findByExample(Role role) throws Exception {
		return getHibernateTemplate().findByExample(role);
	}

	public List<Role> findByProperty(String propertyName, Object value) throws Exception {
			String queryString = "from Role as model where model."+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}
	public List<Role> findAll() throws Exception {
			String queryString = "from Role";
			return getHibernateTemplate().find(queryString);
	}

	public Role merge(Role detachedInstance) throws Exception {
			Role result = (Role) getHibernateTemplate().merge(detachedInstance);
			return result;
	}

	public void attachClean(Role role) throws Exception {
			getHibernateTemplate().lock(role, LockMode.NONE);
	}

	public static RoleDAO getFromApplicationContext(ApplicationContext ctx) {
		return (RoleDAO) ctx.getBean("RoleDAO");
	}
	
	public List<Role> findByHql(String hql,Object value) throws Exception {
		return getHibernateTemplate().find(hql, value);
	}
	
	public List<Role> findByHql(String hql,Object[] values) throws Exception {
		return getHibernateTemplate().find(hql, values);
	}
}